package com.sgb.goods.test;

import android.view.View;

import com.blankj.utilcode.util.ClipboardUtils;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.databinding.GoodsActivityMainBinding;
import com.sgb.goods.utils.base.BaseActivity;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

/**
 * MainActivity
 * module 测试使用
 *
 * @author cyj
 */
public class MainActivity extends BaseActivity<GoodsActivityMainBinding, MainViewModel> {

    @Override
    protected int getLayoutResId() {
        return R.layout.goods_activity_main;
    }

    @Override
    protected void initViewModel() {
        mViewModel = createViewModel(MainViewModel.class, BR.mainViewModel);
        mDataBinding.setMainViewModel(mViewModel);
    }

    @Override
    protected void init() {
        mDataBinding.head.title.setText(getString(R.string.goods_app_module_name));
        mDataBinding.head.ivBack.setVisibility(View.GONE);

    }

    @Override
    protected void initListener() {
        mViewModel.adapter.setOnItemClick(new AdapterOnItemClick<CompanyEntity>() {
            @Override
            public void onItemClick(CompanyEntity companyEntity, int position) {
                mViewModel.settingMainCompany(companyEntity);
            }
        });
        mDataBinding.head.title.setOnClickListener(v -> {
            String token = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.resourcePCToken, "");
            ClipboardUtils.copyText(token);
            MToast.showToast(MainActivity.this, "[已复制在粘贴板]token: /n" + token);
        });
    }
}
